﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bungalow
{
    public partial class AppNotify : UserControl
    {
        public IApp App { get; set; }
        public Uri Uri { get; set; }
        public class AppActionEventArgs
        {
            public IApp App { get; set; }
            public Uri Uri { get; set; }
        }
        public delegate void AppActionEventHandler(object sender, AppActionEventArgs e);
        public event AppActionEventHandler AddApp;
        public event AppActionEventHandler Subscribe;
        public AppNotify()
        {
            InitializeComponent();
        }
        public enum HeaderMode
        {
            Add, Subscribe
        }
        private HeaderMode mode = HeaderMode.Add;
        public HeaderMode Mode
        {
            get
            {
                return mode;
            }
            set
            {
                mode = value;
                switch (mode)
                {
                    case HeaderMode.Add:
                        label1.Text = "Add this app";
                        button1.Text = "Add";
                        break;
                    case HeaderMode.Subscribe:
                        label1.Text = "Subscribe to this view";
                        button1.Text = "Subscribe";
                        break;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
           
                AppActionEventArgs args = new AppActionEventArgs();
                args.App = App;
                args.Uri = Uri;
                switch(mode) {
                    case HeaderMode.Add:
                         if (AddApp != null)
                             AddApp(this, args);
                         break;
                    case HeaderMode.Subscribe:

                         if (Subscribe != null)
                             Subscribe(this, args);
                         break;
            
            }
        }
    }
}
